﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
// Barnhen 1.3 Begin
///using Oracle.DataAccess.Client;
//using Oracle.DataAccess.Types;
using System.Data;
using System.Data.OracleClient;


namespace prjColecao
{
    public class insertItensColecao : databaseConn
    {
        
        public void getConnection() {
            dataConnect();
        }

        // setup values
        public static void setValues(itensColecao item, OracleCommand oraCmd)
        {
            oraCmd.Parameters.AddWithValue("P_NOME_ITEM", item.Nome);
            oraCmd.Parameters.AddWithValue("P_DESCR_ITEM", item.Descricao);
            oraCmd.Parameters.AddWithValue("P_MARCA_ITEM", item.Marca);
            oraCmd.Parameters.AddWithValue("P_FABRICANTE", item.Fabricacao);
            oraCmd.Parameters.AddWithValue("P_ANO_FABRICACAO", item.AnoFabricacao);
        }

        public Boolean insertItemDAO(itensColecao item) {
            try
            {
                getConnection();
                insertDataItem(item);
                return true;

            } catch (Exception EConnection){
                throw new Exception(EConnection.Message);              
            }
        }

        //TIME TO INSERT THE VALUES
        private Boolean insertDataItem(itensColecao item) {
            try
            {
                //sConn.Open(); // to verify
                OracleCommand oraCmd = new OracleCommand();
                oraCmd.Connection = sConn;
                oraCmd.CommandText = "COLECAO.PKG_ITENS_COLECAO.PROC_INS_ITEM_COLECAO";
                oraCmd.CommandType = CommandType.StoredProcedure;
                setValues(item, oraCmd);
                oraCmd.ExecuteNonQuery();
                return true;
            }
            catch (OracleException ErrOra)
            {
                throw new Exception(ErrOra.Message);

            }
            finally
            {
                dataDisconnect();
            }
        
        }
    }
}